clear

use "C:\Users\lenovo\Desktop\WongLiangPOBE\WongLiangStudy2\WongLiangStudy2.dta" 

//treatment group order and choice option
egen time = rowtotal (time1 time2 time3 time4 time5 time6)
replace time = . if time == 0

egen timechoice = rowtotal (time1choice time2choice time3choice time4choice time5choice time6choice)
replace timechoice = . if timechoice == 0

//generate policy type 
egen all_policytype = rowtotal (policytype_time1 policytype_time2 policytype_time3 policytype_time4 policytype_time5 policytype_time6)

//for all order and choice option
egen all_time = rowtotal ( all_time1 all_time2 all_time3 all_time4 all_time5 all_time6)
egen all_timeagree = rowtotal ( all_time1agree all_time2agree all_time3agree all_time4agree all_time5agree all_time6agree)

//generate interaction term of treatment and all_time
gen treatmentXalltime= treatment * all_time

//gen province factor variable
xi i.province

//generate dummy variables for choice of recommended comments, netizens' comments, and skip comments. 
gen recommendeddummy = 0
replace recommendeddummy = . if treatment == 0
replace recommendeddummy = 1 if timechoice == 1

gen netizendummy = 0
replace netizendummy = . if treatment == 0
replace netizendummy = 1 if timechoice == 2

gen skipdummy = 0
replace skipdummy = . if treatment == 0
replace skipdummy = 1 if timechoice == 3


//----------Comment Viewing Trend------------ 

//for treatment group analysis only - set dataset as time series and run multinomial logistic model
tsset id time
sort id time
mlogit timechoice time ini_recommended ini_netizen male age ccp edu _I* income poli_interest news_consumption frequent_use most_recent_use discussion , base(2) vce(cluster id)
estimate store m1

//for treatment group analysis only - declare dataset to be panel data and run random-effects logistic model
xtset id time
xtlogit recommendeddummy time ini_recommended ini_netizen male age ccp edu _I* income poli_interest news_consumption frequent_use most_recent_use discussion , vce(cluster id)
estimate store m2

//generate Table 2 specification 1 and 2
estout *, cells (b(star fmt(%8.3f)) se(par fmt(%8.3f))) stats(N11, fmt(%8.5g)) drop(_I*) starlevels(* 0.05 ** 0.01) style(fixed)
estimate drop *

//***with political attitude questions added***

//for treatment group analysis only - set dataset as time series and run multinomial logistic model
tsset id time
sort id time
mlogit timechoice time ini_recommended ini_netizen male age ccp edu _I* income poli_interest news_consumption frequent_use most_recent_use discussion internal_efficacy external_efficacy resist_west collectivism national_pride info_transparency satisfy_life satisfy_society, base(2) vce(cluster id)
estimate store m1

//for treatment group analysis only - declare dataset to be panel data and run random-effects logistic model
xtset id time
xtlogit recommendeddummy time ini_recommended ini_netizen male age ccp edu _I* income poli_interest news_consumption frequent_use most_recent_use discussion internal_efficacy external_efficacy resist_west collectivism national_pride info_transparency satisfy_life satisfy_society, vce(cluster id)
estimate store m2

//generate Table 2 specification 3 and 4
estout *, cells (b(star fmt(%8.3f)) se(par fmt(%8.3f))) stats(N11, fmt(%8.5g)) drop(_I*) starlevels(* 0.05 ** 0.01) style(fixed)
estimate drop *


// -------------- policy approval ------------------

//for all analysis - set dataset as time series
tsset id all_time 
sort id all_time
//declare dataset to be panel data to use random-effects logistic model 
xtset id all_time

//random-effect logistic of policy approval 
xtlogit all_timeagree all_time treatment treatmentXalltime i.all_policytype male age ccp edu _I* income poli_interest news_consumption frequent_use most_recent_use discussion internal_efficacy external_efficacy resist_west collectivism national_pride info_transparency satisfy_life satisfy_society, vce(cluster id)
estimate store m1

//logistic regression of policy approval 
logit all_timeagree all_time treatment treatmentXalltime i.all_policytype male age ccp edu _I* income poli_interest news_consumption frequent_use most_recent_use discussion internal_efficacy external_efficacy resist_west collectivism national_pride info_transparency satisfy_life satisfy_society, vce(cluster id)
estimate store m2

//generate Table 4 specification 1 and 2
estout *, cells (b(star fmt(%8.3f)) se(par fmt(%8.3f))) stats(N11, fmt(%8.5g)) drop(_I*) starlevels(* 0.05 ** 0.01) style(fixed)
estimate drop *

//generate margins plots for each regression results and generate Figure 7

xtlogit all_timeagree i.treatment##c.all_time i.all_policytype male age ccp edu _I* income poli_interest news_consumption frequent_use most_recent_use discussion internal_efficacy external_efficacy resist_west collectivism national_pride info_transparency satisfy_life satisfy_society, vce(cluster id)
//random-effects marginal plot
margins treatment, at(all_time = (1 2 3 4 5 6))
marginsplot

logit all_timeagree i.treatment##c.all_time i.all_policytype male age ccp edu _I* income poli_interest news_consumption frequent_use most_recent_use discussion internal_efficacy external_efficacy resist_west collectivism national_pride info_transparency satisfy_life satisfy_society, vce(cluster id)
//logistic marginal plot
margins treatment, at(all_time = (1 2 3 4 5 6))
marginsplot




